<?php

namespace app\store\command\mysql;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;

/**
 * 调用mysql存储过程存储统计数据
 * @package app\store\command
 */
class OperateLog extends Command
{
    protected $table_DB_Platform_Account_library = 'db_platform_accounts';           /*平台账户配置库*/
    protected $table_DB_Platform_Account_library_platformdb = 'db_platform_qpplatformdb';
    protected $accounts_info = 'accounts_info';                                      /* 账户表 */
    protected $user_game_cps = 'user_game_cps';                     /*用户CPS用户信息*/
    protected function Db_connect_accounts_info()
    {
        $accounts_info = Db::connect($this->table_DB_Platform_Account_library)->table($this->accounts_info);
        return $accounts_info;
    }
    protected function Db_connect_user_game_cps(){
        $user_game_cps= Db::connect($this->table_DB_Platform_Account_library_platformdb)->table($this->user_game_cps);
        return $user_game_cps;
    }
    /**
     * 配置指令信息
     */
    protected function configure()
    {
        $this->setName('operate_log')->setDescription('调用存储过程把统计数据存表');
    }

    /**
     * 业务指令执行
     * @param Input $input
     * @param Output $output
     */
    protected function execute(Input $input, Output $output)
    {
        // 自动调用存储过程
        $this->autoExecProcedure();
    }
    private function autoExecProcedure()
    {
            // 定义时间年月日 手动指定月份和天数
            $arr =$this->Db_connect_accounts_info()->query('SELECT * from (
SELECT
	UserID,
	NickName,
	RegisterIP,
  count(RegisterIP) as a
FROM
	accounts_info
WHERE
	SpreaderID =1001

GROUP BY 

RegisterIP
) as b WHERE b.a>=10 
');
            foreach($arr as $value){
                $data=$this->Db_connect_accounts_info()->field('RegisterIP,UserID')
                    ->where('TotalRecharge','eq',0)
                    ->where('RegisterIP',$value['RegisterIP'])
                    ->select();
                foreach ($data as $v){
                    $this->Db_connect_user_game_cps()->where('UserID',$v['UserID'])->delete();
                }
            }
        /*$year = '2019';
        $month = '12';
        $start_day = 1;
        $end_day = 18;
        try {
            for (; $start_day <= $end_day; $start_day++) {
                $date = $year . '-' . $month . '-' . $start_day;
                $this->output->highlight($date.' 开始');

                // 手动修改这里需要调用的存储过程
                $sql_call = "call currency_all_type_room('{$date}')";
                Db::connect('db_platform_operatelog')->execute($sql_call);

                $this->output->highlight($date.' 完成');
                $this->output->newLine();
            }
            $this->output->info('全部执行成功');
        }catch (Exception $e){
            $this->output->error($e->getMessage());
        }*/
    }



}
